To write, compile, and run the Hello World Code in Objective-C on Ubuntu, just follow these steps:
- Create a new file in the Home folder and name it “Hello.m”
- Write the following code in your file:
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init ];
NSLog (@"Hello World!");
[pool drain];
return 0;
}
- After saving your file, open the terminal (from the Home folder) and run the following command to compile your code:
gcc $(gnustep-config --objc-flags) -o hello hello.m $(gnustep-config --base-libs)
- To run the generated executable, run the following command:
./hello